package com.qingfeng.coupon.constant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @author zhangyuefei
 * @version 1.0
 * @date 2020/5/26 4:58 下午
 */
@Getter
@AllArgsConstructor
public enum CouponDistributeType {

    BUY_GOODS_DISTRIBUTE(1,"购买商品发放"),
    SPECIFIED_AMOUNT_DISTRIBUTE(2,"消费满金额发放");

    @EnumValue
    private Integer code;

    @JsonValue
    private String description;


    public static CouponDistributeType of(Integer code){
        Objects.requireNonNull(code);
        return Stream.of(values()).
                filter(bean->bean.code.equals(code))
                .findAny()
                .orElseThrow(()->new IllegalArgumentException(code+"not exist"));
    }

    @Override
    public String toString() {
        return "{" +
                "code=" + code +
                ", description='" + description + '\'' +
                '}';
    }
}
